home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.04 Apr 93 / Creating EPSF Files / PSDPort.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-16  |  1.4 KB  |  80 lines  |  [TEXT/KAHL]

  1. /* PSDPort.c */
  2. /* Copyright 1992, Gary D. McGath */
  3.  
  4. /* Routines for monitoring and handling changes in the GrafPort */
  5.  
  6.  
  7. /* Globals */
  8.  
  9. extern void OutputString(char *str, int theFile);
  10.  
  11. void psdSetPenPat(void);
  12. void psdSetFillPat(void);
  13. void OutputGray(double lev);
  14.  
  15. static void psdSetPat(unsigned char *p1);
  16.  
  17. extern int thePSFile;
  18. extern Rect gPSClipRect;
  19.  
  20. double gblGray;                /* last gray level output */
  21. int gblFont;
  22. int gblSize;
  23.  
  24.  
  25. /* Set up defaults for the port. */
  26. void psdInitPort(GrafPtr itsPort)
  27. {
  28.     itsPort->pnSize.h = 1;
  29.     itsPort->pnSize.v = 1;
  30.     gblGray = -1;
  31.     gblFont = -1;
  32.     gblSize = -1;    
  33. }
  34.  
  35. /* Output PostScript code to match the new pattern. "Real" code should
  36.    set up a pattern fill; this one sets the color to black, white, or 50%
  37.    gray depending on the pattern. */
  38. void psdSetPenPat()
  39. {
  40.     psdSetPat((unsigned char *)&thePort->pnPat);
  41. }
  42.  
  43. void psdSetFillPat()
  44. {
  45.     psdSetPat((unsigned char *)&thePort->fillPat);
  46. }
  47.  
  48. static void psdSetPat(unsigned char *p1)
  49. {
  50.     int allWhite = 1;
  51.     int allBlack = 1;
  52.     register int i;
  53.     for (i = 1; i < 8; i++) {
  54.         if (*p1 != 0XFF)
  55.             allBlack = 0;
  56.         if (*p1++ != 0)
  57.             allWhite = 0;
  58.     }
  59.     if (allWhite)
  60.         OutputGray(1.0);
  61.     else if (allBlack)
  62.         OutputGray(0.0);
  63.     else OutputGray(0.5);
  64. }
  65.  
  66.  
  67.  
  68. /* output a gray level, only if it's different from the previous one */
  69. void OutputGray(double lev)
  70. {
  71.     if (lev != gblGray) {
  72.         OutputDouble(lev,thePSFile);
  73.         OutputString("setgray\r",thePSFile);
  74.         gblGray = lev;
  75.     }
  76. }
  77.  
  78.  
  79.  
  80.